local sk__canshi = fk.CreateSkill {

  name = "sk__canshi",

  tags = {},

}



sk__canshi:addEffect(fk.HpRecover, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__canshi.name) and target and target ~= player and not target.dead then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__canshi.name, nil, "#sk__canshi-invoke::" .. target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, { target.id })
    room:addPlayerMark(target, "@sk__canshi", 1)
    room:broadcastProperty(target, "MaxCards")
    player:drawCards(2, sk__canshi.name)
  end,
})
sk__canshi:addEffect(fk.MaxHpChanged, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__canshi.name) and target and target ~= player and not target.dead then
      return data.num > 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__canshi.name, nil, "#sk__canshi-invoke::" .. target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, { target.id })
    room:addPlayerMark(target, "@sk__canshi", 1)
    room:broadcastProperty(target, "MaxCards")
    player:drawCards(2, sk__canshi.name)
  end,
})

sk__canshi:addEffect(fk.EventAcquireSkill, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__canshi.name) and target and target ~= player and not target.dead then
      return player.room:getTag("RoundCount") and data.skill:isPlayerSkill(target) and data.skill.visible
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__canshi.name, nil, "#sk__canshi-invoke::" .. target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, { target.id })
    room:addPlayerMark(target, "@sk__canshi", 1)
    room:broadcastProperty(target, "MaxCards")
    player:drawCards(2, sk__canshi.name)
  end,
})
sk__canshi:addEffect(fk.Damage, {
  name = "sk__canshi",
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(sk__canshi.name) and target and target ~= player and not target.dead then
      return data.to == player
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, sk__canshi.name, nil, "#sk__canshi-invoke::" .. target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:doIndicate(player.id, { target.id })
    room:addPlayerMark(target, "@sk__canshi", 1)
    room:broadcastProperty(target, "MaxCards")
    player:drawCards(2, sk__canshi.name)
  end,
})

sk__canshi:addEffect("maxcards", {
  name = "#sk__canshi_maxcards",
  correct_func = function(self, player)
    return -player:getMark("@sk__canshi")
  end,
})

return sk__canshi
